package top.glkj.hms.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * @author : xgl
 * @version : 0.0.1
 * @date :2020/12/22 3:23
 * 会员用户
 */
@Entity
@Table(name = "hms_vip_user")
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class VipUser extends BaseEntity {
    @OneToOne(targetEntity = User.class,cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(referencedColumnName = "id",name = "user_id")
    private User user;
    /**
     * 会员编号
     */
    @Column(name="member_id")
    public String memberId;
    /**
     * 会员用户住过的房间
     */
    @Fetch(FetchMode.SUBSELECT)
    @ManyToMany(targetEntity = Room.class,cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "hms_vip_user_rooms",
            //当前对象在中间表中的外键
            joinColumns = {@JoinColumn(name = "vip_user_id", referencedColumnName = "id")},
            //对方对象在中间表中的外键
            inverseJoinColumns = {@JoinColumn(name = "room_id", referencedColumnName = "id")}
    )
    public List<Room> lastRoom;
    /**
     * 会员用户的订单信息
     */
    @Fetch(FetchMode.SUBSELECT)
    @ManyToMany(targetEntity = OrderForm.class,cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "hms_vip_user_order_forms",
            //当前对象在中间表中的外键
            joinColumns = {@JoinColumn(name = "vip_user_id", referencedColumnName = "id")},
            //对方对象在中间表中的外键
            inverseJoinColumns = {@JoinColumn(name = "order_form_id", referencedColumnName = "id")}
    )
    public List<OrderForm> orderFormList;
    /**
     * 会员用户喜欢的服务人员
     */
    @OneToOne(targetEntity = Employee.class,cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "employee_id", referencedColumnName = "id")
    public Employee employeeLike;
    /**
     * 会员用户的服务人员
     */
    @Fetch(FetchMode.SUBSELECT)
    @ManyToMany(targetEntity = Employee.class,cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "hms_vip_user_employees",
            //当前对象在中间表中的外键
            joinColumns = {@JoinColumn(name = "vip_user_id", referencedColumnName = "id")},
            //对方对象在中间表中的外键
            inverseJoinColumns = {@JoinColumn(name = "employee_id", referencedColumnName = "id")}
    )
    public List<Employee> employeeList;
    /**
     * 会员用户的生效日期，开始时间
     */
    @Column(name = "start_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date startTime;
    /**
     * 会员用户的生效日期，结束时间
     */
    @Column(name = "end_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date endTime;
    /**
     * 会员用户的付费方式，年费，月费，永久付费
     */
    @Column(name = "payment_methods")
    public String paymentMethods;
    /**
     * 会员用户的折扣
     */
    public double discount;
    /**
     * 余额
     */
    public double balance;
    /**
     * 会员等级
     */
    @Column(name = "vip_level")
    public int vipLevel;
    /**
     * 会员卡密码
     */
    @Column(name = "vip_password")
    public String vipPassWord;

    public VipUser(Long id) {
        super(id);
    }
}
